package com.demo; /**
 * @author wzm
 * @create 2023-06-30 10:31
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/register")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;chatset=UTF-8");

        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String code = request.getParameter("code");
        System.out.println("code = " + code);

        String  scode = (String) request.getSession().getAttribute("sessioncode");
        System.out.println("scode = " + scode);
        //判断验证是否为正确
        if(!code.equalsIgnoreCase(scode)){
            request.setAttribute("smg","验证码错误");
            request.getRequestDispatcher("/register.jsp").forward(request,response);
            return;
        }

        //改写查询数据
        //调用新增
        response.getWriter().write("注册成功");


    }
}
